Vue.component('index-header', {
    data: function () {
        return {
            //登录状态
            loginStatus: false,
            //用户数据
            user: {flag: ""/*未使用*/, nickname: "", username: ""},
            //搜索框内容
            searchcursom: "",
            //发送消息dialog
            sendVisible:false,
            sendVisible:false,
            messageInfo:'',
            theme:'',
            code:0,
        }
    },
    methods: {
        //个人信息下拉框
        handleCommand(command) {
            let count = parseInt(command);
            //已经登录状态
            if (this.loginStatus) {
                switch (count) {
                    case 2:
                        this.getUserAuthorization();
                        break;
                    case 3:

                        break;
                    case 5:
                        //退出登录
                        this.$confirm('此操作将退出登录状态, 是否继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            localStorage.removeItem('localJwt');
                            localStorage.removeItem('currentUserId');
                            localStorage.removeItem("currentNickName");
                            localStorage.removeItem("currentUsername");
                            this.loginStatus = false;
                            this.$message({
                                type: 'success',
                                message: '已成功退出'
                            });
                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '已取消此操作'
                            });
                        })
                        break;
                }
            } else {
                switch (count) {
                    case 1:
                        this.$message.success("开始查询订单");
                        break;
                }
            }
        },
        //输入建议 内部函数 只用传入传入参数就行
        querySearch(queryString, cb) {
            let restaurants = this.restaurants;
            let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        //搜索内容过滤
        createFilter(queryString) {
            return (restaurant) => {
                //查询关键字，只要包含关键字就显示
                return (restaurant.value.indexOf(queryString) !== -1);
            };
        },
        //点击建议内容触发
        handleSelect(item) {
            console.log(item.value);
            //获取搜索框内容
            axios.get("/pa/doctor/selectByName/" + item.value).then(function (res) {
                if (res.data.code == 1) {
                    this.$message.success("搜索成功！");
                    return;
                }
                this.$message.error("搜索失败！")
            })
        },
        //点击搜索按钮
        search() {
            let doctor = this.searchcursom;
            if (doctor !== "") {
                //获取搜索框内容
                axios.get("/pa/doctor/selectByName/" + doctor).then(function (res) {
                    if (res.data.code === 1) {
                        this.$message.success("搜索成功！");
                        return;
                    }
                    this.$message.error("搜索失败！")
                })
            }
        },
        //获取用户数据
        getUserDetails() {
            this.user.nickname = localStorage.getItem("currentNickName");
            this.user.username = localStorage.getItem("currentUsername");
            if (this.user.nickname !== null && this.user.nickname.length !== 0 && this.user.nickname!=='undefined') {
                this.loginStatus = true;
            }else {
                this.loginStatus = false;
            }
        },
        //获取用户token数据，查看是否有权限操作
        getUserAuthorization() {location.href = "/beforeIndex/patientsManage.html"},
        //发送消息
        sendMessage(){
            this.sendVisible=true;
            console.log(this.sendVisible)
        },
        //发送消息数据请求
        sendMessageData(){
            let userId = localStorage.getItem("currentUserId");
            let messageInfo={theme:'',content:'',userId:''}
            messageInfo.theme=this.theme;
            messageInfo.content=this.messageInfo;
            messageInfo.userId=userId;
            axios.post("/pa/feedback/send",messageInfo,{headers: {token: localStorage.getItem("localJwt")}}).then(function (res) {
                   this.code=res.data.code;
            })
            this.$notify({
                title: '成功',
                message: '发送成功!',
                type: 'success',
                duration:2000
            });
        },
    },
    //页面渲染之后再进行调用
    mounted() {
        this.restaurants = this.doctor;
        this.getUserDetails();
    },
    //页面渲染之前进行调用
    created: function () {
    },
    template: `

            <el-row>
                <el-col span="20" offset="2">
                    <el-card class="header-card" shadow="hover">
                        <el-row style="margin-top: -20px;" gutter="10">
                            <el-col span="4">
                                <h2>医院预约挂号系统</h2>                            
                            </el-col>
                            <el-col offset="16" span="2">
                                <el-dropdown trigger="click">
                                    <el-button type="text" style="color: #333333">消息反馈<i class="el-icon-caret-bottom el-icon--right"></i></el-button>
                                    <el-dropdown-menu slot="dropdown">
                                     <el-popover placement="bottom" width="400" title="发送反馈" trigger="click">
                                       <el-input type="text" style="width: 250px" placeholder="输入标题" v-model="theme" maxlength="10" show-word-limit>
                                        </el-input>
                                        <el-input type="textarea" v-model="messageInfo"></el-input>
                                         <el-button type="success" @click="sendMessageData" icon="el-icon-check" circle style="margin-top: 10px;float: right"></el-button>
                                        <el-dropdown-item slot="reference" @click.native="sendMessage" class="clearfix">发送反馈</el-dropdown-item>
                                         </el-popover>
                                         <el-popover placement="right" width="400" trigger="click">
                                         <span>123</span>
                                        <el-dropdown-item class="clearfix">我的回复<el-badge class="mark" :value="3" /></el-dropdown-item>
                                        </el-popover>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </el-col>
                            <div v-if="loginStatus==true">
                                <el-col span="2">
                                    <el-dropdown @command="handleCommand" placement="bottom">
                                        <el-link :underline="false">{{user.nickname}}</el-link>
                                        <el-dropdown-menu slot="dropdown">
                                            <el-dropdown-item @click.native="location.href='/beforeIndex/alterInformation.html'">个人信息</el-dropdown-item>
<!--                                            <el-dropdown-item command="2">就诊人管理</el-dropdown-item>-->
                                             <el-dropdown-item command="3">修改密码</el-dropdown-item>
                                            <el-dropdown-item command="5" divided>退出登录</el-dropdown-item>
                                        </el-dropdown-menu>
                                    </el-dropdown>
                                </el-col>
                            </div>
                            <div v-else>
                                <el-col span="2">
                                    <el-dropdown @command="handleCommand" placement="bottom">
                                        <el-link :underline="false" @click="location.href='/login.html'">登录/注册</el-link>
                                    </el-dropdown>
                                </el-col>
                            </div>
                        </el-row>
                    </el-card>
                </el-col>
            </el-row>
            
  
    `
})
